package ro.prjmanager.core.list;

/**
 * AnalyzeErrorsBase.java
 * <p/>
 * Copyright (c) 2009 Viorel Tacliciu. All Rights Reserved.
 * <p/>
 * This source file may not be copied, modified or redistributed,
 * in whole or in part, in any form or for any reason, without the express
 * written consent of Viorel Tacliciu.
 */
public class TabelOutJson {
    int page;
    int total;
    RowJson[] rows;
    int records;

    public TabelOutJson(int rowNo,int total,int page,int resRows,int records){
        rows=new RowJson[resRows];
        if(total%rowNo==0)
            this.total=total/rowNo;
        else this.total=total/rowNo+1;
        this.page=page;
        this.records=records;
    }

    public void setRowByNo(int rowNo, RowJson row){
        rows[rowNo]=row;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public RowJson[] getRows() {
        return rows;
    }

    public void setRows(RowJson[] rows) {
        this.rows = rows;
    }
    
     public static final String NL ="\n" ;
     public String toJson(){
        
        StringBuilder sb=new StringBuilder();
        
            sb.append("{").append(NL);
            sb.append("page: ").append(page).append(",").append(NL);
            sb.append("total: ").append(total).append(",").append(NL);
            sb.append("records : ").append(records).append(",").append(NL);
            sb.append("rows: [").append(NL);
         int p=0;
            if(rows!=null&&rows.length>0)
            for(RowJson row:rows){

                sb.append("{id: ").append("'").append(row.getId()).append("',cell:[").append(row.getCell()).append("]}");
                if(p<rows.length-1)
                    sb.append(",");
                sb.append(NL);
                p++;
            }
         sb.append("]").append(NL).append("}");
         return sb.toString();
    }
}
